package com.biao.transaction.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biao.transaction.example.entity.OperateB;
import com.biao.transaction.example.mapper.OperateBMapper;
import com.biao.transaction.example.service.OperateBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenwenbiao
 * @since 2020-04-23
 */
@Service
public class OperateBServiceImpl extends ServiceImpl<OperateBMapper, OperateB> implements OperateBService {

    @Autowired
    private OperateBMapper operateBMapper;

    @Override
    public void noTransaction(String name) {
        OperateB operateB = new OperateB(name);
        save(operateB);
    }

    @Override
    public void noTransactionThrowException(String name) {
        OperateB operateB = new OperateB(name);
        save(operateB);

        int x = 1/0;
    }

    @Transactional
    @Override
    public void hasTransaction(String name) {
        OperateB operateB = new OperateB(name);
        save(operateB);
    }

    @Transactional
    @Override
    public void hasTransactionThrowException(String name) {
        OperateB operateB = new OperateB(name);
        save(operateB);

        int x = 1/0;
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void hasNewTransaction(String name) {
        OperateB operateB = new OperateB(name);
        save(operateB);
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void hasNewTransactionThrowException(String name) {
        OperateB operateB = new OperateB(name);
        save(operateB);

        int x = 1/0;
    }


}
